package com.situ.lession1226.api;



import com.github.pagehelper.PageInfo;
import com.situ.lession1226.model.News;
import com.situ.lession1226.model.News;
import com.situ.lession1226.service.NewsService;
import com.situ.lession1226.service.NewsService;
import com.situ.lession1226.util.PaginateInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 *
 *
 *返回不同分类的电影列表
 */
@RestController
@RequestMapping(value = "/api/v1/category", produces = "application/json;charset=utf-8")
public class CategoryApi {
    private NewsService newsService;

    @Autowired
    public void setNewsService(NewsService newsService) {
        this.newsService = newsService;
    }


//    返回一个类别的电影列表
    @GetMapping
    public Map<String, Object> list(@RequestParam(defaultValue = "1") Integer pageNo,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                    News news) {
        //创建一个分页对象
        PaginateInfo pi = PaginateInfo.of(pageNo, pageSize);

        List<News> Newss = newsService.findAll(pi, news);

        //PageHelper的分页对象
        PageInfo<?> pif = pi.getPageInfo();

        return Map.of("news", Newss, "success", true, "pi", pif);
    }
}
